import Vue from "vue";
import VueRouter from "vue-router";
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

VueRouter.prototype.replace = function replace(location, onResolve, onReject) {
    if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
    return originalReplace.call(this, location).catch(err => err)
}

const routes = [
    {
        path: '/',
        component: Login,
        name: 'Login',
        hidden: true
    },
    {
        path: '/home',
        name: '首页',
        component: () => import( '../views/Home'),
        children: [{
            path: '/index',
            component: () => import('../views/Index')
        } ]
    }

]

const router = new VueRouter({
    routes
})

export default router